<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@page import="com.message.dao.ConnectionPool"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'listMessage.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<%!int pages,total; %>
    <%
    if(request.getParameter("page")==null){//没有页码，显示第一页
    	 pages = 0;
    }else{
    	pages = Integer.parseInt(request.getParameter("page"));
    	if(pages<0) pages =0;
    	if(pages>(total+4)/5-1) pages= (total+4)/5-1;
    }
    Connection conn = ConnectionPool.getConnection();
    String sql="SELECT count(*) from guestmessage";
    ResultSet rs  = conn.createStatement().executeQuery(sql);
    rs.next();
    total = rs.getInt(1);
    PreparedStatement st = conn.prepareStatement("SELECT title,content,userName,time,ip FROM guestmessage order by time desc limit ?,5");
    st.setInt(1,pages * 5);
    rs = st.executeQuery();
    int i=1;
    while(rs.next()){
    	%>
    	<hr>
    	第<%=pages * 5 + i++%>条消息
    	消息标题:<%=rs.getString(1) %><br>
    	消息内容:<%=rs.getString(2) %><br>
    	发送人:<%=rs.getString(3) %><br>
    	发送时间:<%=rs.getString(4) %><br>
    	IP:<%=rs.getString(5) %><br>
    	<% 
    	 
    	
    }
    rs.close();
    	conn.close();%>
    
    <a href="listMessage.jsp?page=<%=pages+1 %>">下一页</a>  <a href="listMessage.jsp?page=<%=pages-1 %>">上一页</a>当前第<%=pages+1 %>页 共<%=(total+4)/5 %>页（<%=total %>条记录）
  </body>
</html>
